<template>
  <div class="app-container">
  <div class="filter-container">
        <el-input clearable v-model="search.number" placeholder="供应商" style="width: 170px;margin-left:0px;"></el-input>
        
        <el-date-picker v-model="search.daterange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="margin-left:10px;">
        </el-date-picker>

        <el-button type="primary" icon="el-icon-search" @click="searchClick()" style="margin-left:10px;">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" 
      border fit highlight-current-row stripe  style="width: 100%">

      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>

      <el-table-column  min-width="100" align="center" label="供应商名称">
        <template slot-scope="scope">
          <span>{{ scope.row.supplier }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="采购单数">
        <template slot-scope="scope">
          <span>{{ scope.row.count }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="总金额">
        <template slot-scope="scope">
          <span>{{ scope.row.totalmoney }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="返利计提额">
        <template slot-scope="scope">
          <span>{{ scope.row.rebatemoney }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="状态">
        <template slot-scope="scope">
          <span>{{ scope.row.state  }}</span>
        </template>
      </el-table-column>
      
      <el-table-column  min-width="100" align="center" label="日期">
        <template slot-scope="scope">
          <span>{{ scope.row.createtime | parseTime('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作"  width="280" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="tableRowClick().receipt(scope.row.id)">实收</el-button>
          <el-button type="primary" size="small" @click="tableRowClick().details(scope.row.id)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.rows" @pagination="fetchData" />

<!-- 计提 -->
<el-dialog :title="dialogReceipt.title" :visible.sync="dialogReceipt.visible"  width="900px">
    <div class="ci">
        <div class="bill" ref="dialogLoanBill">
          <div class="item">1、摘要：支付******供应商车款 已支付</div>
          <div class="item">2、科目：</div>
          <div class="item">借1：113200n 预付账款-***单位 金额=23409.00元</div>
          <div class="item">
            贷1：113300n 中国银行 36月按揭贷款 金额=360000.00元
          </div>
          <div class="item">贷2：融资支付 210100n 金额=360000.00元</div>
          <div class="item">
            贷3：厂家返利支付， 1133 单位：**** 金额=360000.00元
          </div>
        </div>
    </div>
    <div slot="footer" class="dialog-footer">
        <el-button   @click="dialogReceipt.visible = false">关 闭</el-button>
        <el-button  type="primary" @click="dialogReceipt.visible = false">保 存</el-button>
    </div>
</el-dialog>
<!-- end 计提 -->

<!-- 计提 -->
<el-dialog :title="dialogDetails.title" :visible.sync="dialogDetails.visible"  width="900px">
    <div class="ci">
        <div class="item">
            <span class="name">采购单号：</span>
            <span class="value"></span>
        </div>
        <div class="item">
            <span class="name">采购付款类型：</span>
            <span class="value"></span>
        </div>
        <div class="item">
            <span class="name">计提日期：</span>
            <span class="value"></span>
        </div>
        <div class="item">
            <span class="name">供应商名称：</span>
            <span class="value"></span>
        </div>
        <div class="item">
            <span class="name">付款类型：</span>
            <span class="value"></span>
        </div>
        <div class="item">
            <span class="name">配件名称：</span>
            <span class="value"></span>
        </div>
        <div class="item">
            <span class="name">入库成本：</span>
            <span class="value"></span>
        </div>
        <div class="item">
            <span class="name">制单人：</span>
            <span class="value"></span>
        </div>
    </div>
    <div slot="footer" class="dialog-footer">
        <el-button   @click="dialogDetails.visible = false">关 闭</el-button>
    </div>
</el-dialog>
<!-- end 计提 -->

  </div>
</template>

<script>
import * as partsApi from '@/api/finance/parts'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import * as enumHelper from '@/utils/enum'

export default {
    components: { Pagination },
    data(){
        return{
            enableProcesscyle:true,
            search:{ 
                number:'',
                customer:'',
                phone:'',
                daterange:'',
            },
            listQuery: {
                    page: 1,
                    rows: 20,
                    name:'',
                    phone:'',
                    state:-1,
            },
            list:null,
            listLoading:false,
            total:0,
            selectOptions:{
                takers:[]
            },

            dialogReceipt:{
                visible:false,
                saveloading:false,
                title:'计提',
                data:{
                }
            },
            dialogDetails:{
                visible:false,
                saveloading:false,
                title:'批量计提',
                data:{
                }
            },
            
        }
    },
    created(){
        var that=this;
        //初始化下拉菜单
        //enumHelper.initOptions(that.selectOptions.salesState,enumHelper.presale.salesState);
        that.fetchData();
    },
    filters:{
      parseFixType(val){
        return enumHelper.aftersale.fixType.getName(val);
      },
      parseFixCategory(val){
        return enumHelper.aftersale.fixCategory.getName(val);
      },
      parseClaimdamageState(val){
        return enumHelper.aftersale.claimdamageState.getName(val);
      }

    },
    methods:{
        fetchData(){
          var that=this;
            partsApi.getRebateReceiptList({}).then(res=>{
              if(res.data){
                that.list=[...res.data.items.map((item,index)=>{
                  item._id=index+1;
                  return item;
                })];
                that.total=res.data.total;
              }
            })
        },
        refreshClick(){
            this.fetchData();
        },
        mutilAccrualClick(){
            this.dialogDetails.visible=true;
        },
        
        tableRowClick(){
            var that=this;
            return {
                receipt(id){
                    that.dialogReceipt.visible=true;
                },
                details(id){
                    that.dialogDetails.visible=true;
                },
            }
        }

    }
}
</script>

<style>

</style>